export const menuCheck = {
  components:{
  },
  data() {
    return {
    }
  },
  mounted() {
  },
  methods: {
    async clickItem(item) {
		console.log('item', item)
		// 如果没有跳转链接不执行以下操作
		if (item.routerPath == '') {
			return;
		}
		// 我的页面基础配置菜单直接跳转
		if (item.name == '消息通知' || item.name == '安全中心' || item.name == '设置' || item.name == '个人信息') {
			this.goTo(item)
			return;
		}
    	// 权限校验
    	let token = uni.getStorageSync('token')
    	let isAuth = uni.getStorageSync('isAuth')
    	if (token && isAuth) {
    		this.goTo(item)
    	} else {
    		let reqData = {
    			menuId: item.itemId
    		}
    		const [err, res] = await this.$singleMenuCheck(reqData);
    		// 根据结果进行处理
    		if (res) {
    			console.log('singleMenuCheck', res)
    			if (!token) {
    				if (res.needLogin) {
    					uni.redirectTo({
    						url: '/pages/index/authorize'
    					})
    					return;
    				}
    			}
    			if (!isAuth) {
    				if (res.needFillInfoType.includes('IDCARDNO_AND_NAME')) {
    					uni.showModal({
    					    title: '提示',
    					    content: '此菜单权限需要用户认证，去认证',
    					    success: function (res) {
    					        if (res.confirm) {
    					            uni.navigateTo({
    					            	url: '/pages/index/authentication'
    					            })
    					        } else if (res.cancel) {
    					            console.log('用户点击取消');
    					        }
    					    }
    					});
    					return;
    				}
    			}
    			this.goTo(item)
    		} else {
    		}
    	}
    	
    },
    
    goTo(item) {
		// routerType 1：内部地址 2：外部H5地址 3：外部小程序
    	let type = item.routerType;
    	if (type == 1) {
    		uni.navigateTo({
    			url: item.routerPath,
    			success:res =>{},
    			fail:() =>{},
    			complete:() => {}
    		});
    	} else if (type == 2) {
			// TODO 跳转外部H5页面更新token
    		uni.navigateTo({
    			url: item.routerPath + '&explain=' + item.name,
    			success:res =>{},
    			fail:() =>{},
    			complete:() => {}
    		});
    	} else if (type == 3) {
    		uni.navigateToMiniProgram({
    			appId: item.routerPath,
    			path: '',
    			extraData: {
    			},
    			success(res) {
    				// 打开成功
    			}
    		})
    	}
    }
  }
}